package com.hundsun.yr.universal.p2p.bean;

import com.hundsun.yr.universal.library.utils.HsDateUtils;
import com.hundsun.yr.universal.library.utils.MathUtils;

import android.text.TextUtils;



/**
 * @Title: MineLoan.java 
 * @Description: 我的借款
 * @date 2016-1-21 下午4:31:54 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class MineLoan {
	
	/**
	 * 取值的key
	 */
	public static String BASEKEY="myBorrowInfoVOs";
	/**
	 * 刷新code
	 */
	public static final int REFRESH=10001;

	/**
	 * 申请编号
	 */
	public static String APPLYID="applyId";
	/**
	 * 借款金额
	 */
	public static String BORROWAMOUNT="borrowAmount";
	/**
	 * 借款期限
	 */
	public static String BORROWPERIOD="borrowPeriod";
	/**
	 * 借款期限单位
	 */
	public static String BORROWPERIODUNIT="borrowPeriodUnit";
	/**
	 * 借款利率
	 */
	public static String BORROWRATE="borrowRate";
	/**
	 * 商品编号
	 */
	public static String GOODSID="goodsId";
	/**
	 * 商品状态（从商品拿，进行转换）NOT_CONFIRM("0", "待提交"),
    NOT_CHECK("1", "待审核"),
    CHECK_REJECT("2", "已退回"),
    CANCEL("3", "已取消"),
    INITIAL("4","已审核"),
    IN_RAISED("5","募集中"),
    STOP_SALES("6","停止销售"),
    FAILURE_BID("7","流标"),
    PENDING_LOAN("8","待放款"),
    PENDING_REPAYMENT("9","待还款"),
    IN_REPAYMENT("10","还款中"),
    HAS_SETTLED("11","已还清");
	 */
	public static String GOODSSTATUS="goodsStatus";
	/**
	 * 加点利率
	 */
	public static String INCREMENTRATE="incrementRate";
	/**
	 * 信贷产品编号
	 */
	public static String PRODUCTID="productId";
	/**
	 * 信贷产品名称
	 */
	public static String PRODUCTNAME="productName";
	/**
	 * 还款利率（借款利率+加点利率）
	 */
	public static String REFUNDRATE="refundRate";
	/**
	 * 还款方式 ONCE_TIME("1","到期还本付息"),//到期还本付息  MONTH_PROFIT("2","按月付息到期还本"),//先息后本  QUARTER_PROFIT("3","按季付息到期还本"),//先息后本 HALFYEAR_PROFIT("4","按半年付息到期还本"),//先息后本 MONTH_AMT("5","按月等额本息"),//等额本息MONTH_PRINCIPAL("6","按月等额本金");
	 */
	public static String REFUNDWAY="refundWay";
	/**
	 * 服务费率(手续费率)
	 */
	public static String SERVICERATE="serviceRate";
	/**
	 * 租户ID
	 */
	public static String TENANTID="tenantId";
	
	/**
	 * 用户编号
	 */
	public static String USERNO="userNo";
	
	/**
	 * 已募集金额
	 */
	public static String HASIVSMMNY="hasIvsmMny";
	/**
	 * 募集进度
	 */
	public static String RAISEPROGRESS="raiseProgress";
	/**
	 * 还款倒计时 （还款计划计算）
	 */
	public static String DOWNDAY="downDay";
	/**
	 * 发布日期 （营销）
	 */
	public static String RELEASEDATE="releaseDate";
	 /** 
	  * 起息日 （营销，产品成立日+1）
	  */
	public static String INTERESTDAY="interestDay";
	/** 
	  * 放款日期
	  */
	public static String LOANPAYCHECKTIME="loanPayCheckTime";
	
	/**
	 * 修改日期（还清的状态下，就是还清日期）
	 */
	public static String UPDATETIME="updateTime";
	/**
	 * 借款日期（创建日期）
	 */
	public static String CREATETIME="createTime";
	/**
	 * 还清日期
	 */
	public static String FINISHREFUNDTIME="finishRefundTime";
	
	/**
	 * 还款方式转换
	 * @param refundway 还款方式
	 * @return String
	 */
	public static String return_way(String refundway){
		String way="";
		if(TextUtils.isEmpty(refundway)){
			return way;
		}
		
		if(TextUtils.equals(refundway, "ONCE_TIME")){
			way="到期还本付息";
		}else if(TextUtils.equals(refundway, "MONTH_PROFIT")){
			way="按月付息到期还本";
		}else if(TextUtils.equals(refundway, "QUARTER_PROFIT")){
			way="按季付息到期还本";
		}else if(TextUtils.equals(refundway, "HALFYEAR_PROFIT")){
			way="按半年付息到期还本";
		}else if(TextUtils.equals(refundway, "MONTH_AMT")){
			way="按月等额本息";
		}else if(TextUtils.equals(refundway, "MONTH_PRINCIPAL")){
			way="按月等额本金";
		}
		
		return way;
	}
	
	
	/**
	 * 还款单位
	 * @param refundway
	 * @return
	 */
	public static String borrowPeriod(String borrowPeriodUnit){
		String way="天";
		if(TextUtils.isEmpty(borrowPeriodUnit)){
			return way;
		}
		if(TextUtils.equals(borrowPeriodUnit, "DAY")){
			way="天";
		}else if(TextUtils.equals(borrowPeriodUnit, "MONTH")){
			way="月";
		}else if(TextUtils.equals(borrowPeriodUnit, "YEAR")){
			way="年";
		}
		
		return way;
	}
	
	
	/**
	 * 还款时间
	 * @param refundway
	 * @return
	 */
	public static String borrowPeriodDay(String borrowPeriodUnit,String borrowPeriod){
		String day="0";
		if(TextUtils.isEmpty(borrowPeriodUnit)){
			return day;
		}
		if(TextUtils.equals(borrowPeriodUnit, "DAY")){
			day=borrowPeriod;
		}else if(TextUtils.equals(borrowPeriodUnit, "MONTH")){
			day=MathUtils.multiply(borrowPeriod,"30");
		}else if(TextUtils.equals(borrowPeriodUnit, "YEAR")){
			day=MathUtils.multiply(borrowPeriod,"360");;
		}
		
		return day;
	}
    
	
	
	/**
	 * 商品状态（从商品拿，进行转换）
	 */
	public enum EnumGoodsState {
		NOT_CONFIRM("NOT_CONFIRM", "待提交"),
	    NOT_CHECK("NOT_CHECK", "待审核"),
	    CHECK_REJECT("CHECK_REJECT", "已退回"),
	    CANCEL("CANCEL", "已取消"),
	    INITIAL("INITIAL","已审核"),
	    IN_RAISED("IN_RAISED","募集中"),
	    STOP_SALES("STOP_SALES","停止销售"),
	    FAILURE_BID("FAILURE_BID","流标"),
	    PENDING_LOAN("PENDING_LOAN","待放款"),
	    PENDING_REPAYMENT("PENDING_REPAYMENT","待还款"),
	    IN_REPAYMENT("IN_REPAYMENT","还款中"),
	    HAS_SETTLED("HAS_SETTLED","已还清");
	    /** 状态描述 **/
	    private String description;
	    /** 状态 **/
	    private String status;

	    /**
	     * 私有构造方法
	     * @param description 描述
	     **/
	    private EnumGoodsState(String status,String description) {
	        this.status = status;
	        this.description = description;
	    }

	    /**
	     * 根据描述查找枚举
	     * 
	     * @param description 编码
	     * @return EnumSTATUS
	     **/
	    public static EnumGoodsState find(String description) {
	        for (EnumGoodsState frs : EnumGoodsState.values()) {
	            if (frs.getDescription().equals(description)) {
	                return frs;
	            }
	        }
	        return null;
	    }
	    /**
	     * 根据枚举查找描述
	     * 
	     * @param status 枚举
	     * @return String
	     **/
	    public static String getDescription(String status) {
	    	for (EnumGoodsState frs : EnumGoodsState.values()) {
	            if (frs.status.equals(status)) {
	                return frs.description;
	            }
	        }
			return status;
	    }
	    
	    public String getDescription() {
	        return description;
	    }
	}
	
	
	/**
	 *结束日
	 * @param startDay
	 * @param downDay
	 * @return
	 */
	public static String endDate(String startDay,String downDay){
		
		long end=MathUtils.string2long(startDay)+MathUtils.string2int(downDay)*24L*3600000L;
		
		return HsDateUtils.timeformat(HsDateUtils.farmat_date_4, end);
	}
	
}
